Skip to content

GH-3930: Add Jackson 3 support; deprecate Jackson 2 #3996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sobychacko
Copy link
Contributor

Fixes: #3930

  • Manage dependencies, similar way we do for Jackson 2
  • Add Jackson 3 counterparts for existing Jackson 2 based classes (mostly copy/paste)
  • Deprectate Jackson 2 classes
  • Update tests
  • Initial round of updates in docs

Fixes: spring-projects#3930

* Manage  dependencies, similar way we do for Jackson 2
* Add Jackson 3 counterparts for existing Jackson 2 based classes (mostly copy/paste)
* Deprectate Jackson 2 classes
* Update tests
* Initial round of updates in docs

Signed-off-by: Soby Chacko <[email protected]>
*/
public DefaultJacksonKafkaHeaderMapper(String... patterns) {
this(JsonMapper.builder()
.findAndAddModules(JacksonJsonMessageConverter.class.getClassLoader())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class loader from this class exactly, not something else to avoid class tangle and so.

* Create an instance for inbound mapping only with pattern matching.
* @param patterns the patterns to match.
* @return the header mapper.
* @since 2.8.8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No @since on methods in all new classes, please.

Object value = decodeValue(header, type);
headers.put(header.key(), value);
}
catch (IOException e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be revised since Jackson 3 does not throw IOException any more.
May just catch (Exception e) { instead?

@@ -101,6 +103,9 @@ public BatchMessagingMessageConverter(@Nullable RecordMessageConverter recordCon
if (JacksonPresent.isJackson2Present()) {
this.headerMapper = new DefaultKafkaHeaderMapper();
}
else if (JacksonPresent.isJackson3Present()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's prefer Jackson 3!
If they have both in classpath, so Jackson 3 choice would win.

* On the producer side, select a subclass that matches the corresponding
* Kafka Serializer.
*
* @author Soby Chacko
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, honor authors of class we are deprecating.


private JacksonJavaTypeMapper typeMapper = new DefaultJacksonJavaTypeMapper();

private final TypeFactory typeFactory = TypeFactory.createDefaultInstance();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use ObjectMapper.getTypeFactory() instead in the ctor!

import org.springframework.util.Assert;

/**
* A {@link MessageConverter} implementation based on Jacthat uses a Spring Data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably meant based on Jackson 3 😄

@@ -263,6 +265,13 @@ project ('spring-kafka') {
exclude group: 'org.jetbrains.kotlin'
}

optionalApi 'tools.jackson.core:jackson-databind'
optionalApi 'tools.jackson.datatype:jackson-datatype-joda'
optionalApi 'tools.jackson.dataformat:jackson-dataformat-xml'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't do XML here in Spring Kafka, so let's just remove this redundant dependency!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix deprecation for the MappingJacksonParameterizedConverter
2 participants